<?php 
class Staff_Model {
	/**
	 * Holds instance of database connection
	 */
	private $db;
	private $page_data = array();
	private $staff_number = 1;
	public function __construct()
	{
		$this->db = new MysqlImproved_Driver;
	}
	public function get_all_staff()
	{		
		//connect to database
		$this->db->connect();
		$this->get_page_data();
		$article['page_title'] = $this->page_data['title'];
		$article['page_description'] = $this->page_data['description'];
		$article['page_keywords'] = $this->page_data['keywords'];
		$this->get_the_data_of_senior_staff();
		$article['senior_staff_content'] = $this->senior_staff_content;
		$this->get_lowerlevel_personnel_data();
		$article['company_personel_content'] = $this->lowerlevel_staff_content;
		return $article;
	}
	
	public function get_the_data_of_senior_staff(){
		// prepare query
		$this->db->prepare(
				"
				SELECT
				`staff_link`,
				`staff_image`,
				`staff_name`,
				`staff_email`,
				`staff_position`,
				`staff_description`
				FROM
				`senior_staff`
				ORDER 
				BY
					`id`
				ASC
				;
				"
				);
		$this->db->query();
		$this->senior_staff_content = "";
		while($staff_data = $this->db->fetch('array')){
			if($this->staff_number == 1){
				$this->senior_staff_content .= "
				<div class=\"item has-more\">
				<a class=\"lightbox\" href=\"../images/staff/".$staff_data['staff_image']."\" title=\"".$staff_data['staff_name']."\"><img class=\"left\" src=\"/images/staff/".$staff_data['staff_image']."\" alt=\"".$staff_data['staff_description']."\" /></a>
				<div class=\"item-info\">
				<h4 class=\"item-h left\">".$staff_data['staff_name']."</h4>
				<a href=\"mailto:".$staff_data['staff_email']."\"><img class=\"left mail\" src=\"../images/ico-mail.png\" alt=\"send e-mail\" /></a>
				<span class=\"right\">".$staff_data['staff_position']."</span>
					
				<div class=\"item-parag clear\">
				<p>
				".$staff_data['staff_description']."
				</p>
				</div>
				<a class=\"more-arr\" href=\"/senior-staff/".$staff_data['staff_link']."\"></a>
					
				</div>
				</div>
				<!-- End Staff Item -->
				";
			}
			else {
				$this->senior_staff_content .= "
				<div class=\"item\">
						<a class=\"lightbox\" href=\"/images/staff/".$staff_data['staff_image']."\" title=\"".$staff_data['staff_name']."\"><img class=\"left\" src=\"/images/staff/".$staff_data['staff_image']."\" alt=\"".$staff_data['staff_description']."\" /></a>
						<div class=\"item-info\">
							<h4 class=\"item-h left\">".$staff_data['staff_name']."</h4>
							<a href=\"mailto:".$staff_data['staff_email']."\"><img class=\"left mail\" src=\"../images/ico-mail.png\" alt=\"send e-mail\" /></a>
							<span class=\"right\">".$staff_data['staff_position']."</span>
							
							<div class=\"item-parag clear\">
								<p>
								".$staff_data['staff_description']."
								</p>
							</div>
							<a class=\"more-arr\" href=\"/senior-staff/".$staff_data['staff_link']."\"></a>
							
						</div>
					</div>
					<!-- End Staff Item -->
				";
			}
			$this->staff_number++;
		}
		return $this->senior_staff_content;
	}
	
	public function get_lowerlevel_personnel_data(){
		// prepare query
		$this->db->prepare(
				"
				SELECT
				`staff_link`,
				`staff_name`,
				`staff_email`,
				`staff_position`,
				`staff_description`
				FROM
				`lowerlevel_staff`
				ORDER
				BY
				`id`
				ASC
				;
				"
		);
		$this->db->query();
		$this->lowerlevel_staff_content = "";
		while($staff_lower_data = $this->db->fetch('array')){
			if($this->staff_number == 1){
				$this->lowerlevel_staff_content .= "
				<div class=\"item has-more\">
				<div class=\"item-info\">
				<h4 class=\"item-h left\">".$staff_lower_data['staff_name']."</h4>
				<a href=\"mailto:".$staff_lower_data['staff_email']."\"><img class=\"left mail\" src=\"../images/ico-mail.png\" alt=\"send e-mail\" /></a>
				<span class=\"right\">".$staff_lower_data['staff_position']."</span>
					
				<div class=\"item-parag clear\">
				<p>
				".$staff_lower_data['staff_description']."
				</p>
				</div>
				<a class=\"more-arr\" href=\"/personel/".$staff_lower_data['staff_link'].".html\"></a>
					
				</div>
				</div>
				";
			}
			else {	
				$this->lowerlevel_staff_content .= "
					<div class=\"item\">
						<div class=\"item-info\">
							<h4 class=\"item-h left\">".$staff_lower_data['staff_name']."</h4>
							<a href=\"mailto:".$staff_lower_data['staff_email']."\"><img class=\"left mail\" src=\"../images/ico-mail.png\" alt=\"send e-mail\" /></a>
							<span class=\"right\">".$staff_lower_data['staff_position']."</span>
							
							<div class=\"item-parag clear\">
								<p>
								".$staff_lower_data['staff_description']."
								</p>
							</div>
							<a class=\"more-arr\" href=\"/personel/".$staff_lower_data['staff_link'].".html\"></a>
							
						</div>
					</div>
				";
			}
			$this->staff_number++;
		}
		return $this->lowerlevel_staff_content;
	}
	
	public function get_page_data(){
		//prepare query
		$this->db->prepare
		(
				"
				SELECT
				`page`,
				`title`,
				`description`,
				`keywords`
				FROM
				`page_description`
				WHERE
				`page` = 'staff'
				LIMIT
				1
				;
				"
		);
		
		//execute query
		$this->db->query();

		$this->page_data = $this->db->fetch('array');
		return $this->page_data;
	}
	
}